<?php
namespace Tlf\BigDb;
/**
* Integrate with LilDb's LilMigrations class, to handle database versioning
*/
trait Migrations {
/**
* Migrate up or down between the library's database versions
*
* @param $version_from the current database version - pass `0` (zero) if database has not been created.
* @return void
*
* @override to use a different migration scheme than LilDb's LilMigrations class
*/
public function migrate(int $version_from, int $version_to){
if (!isset($this->sql)){
$this->init_sql();
}
$lm = new \Tlf\LilMigrations($this->pdo, $this->get_migration_dir());
$lm->migration_vars = $this->get_migration_vars();
$lm->migrate($version_from, $version_to);
}
/**
* Get the full path to a directory containing migrations. See LilDb's LilMigrations at https://gitlab.com/taeluf/php/lildb
* @return a directory path, which should contain sub-directories like `v1`, `v2`, and so on.
*
* @override if your migration dir is not at your `root_dir/migrate/`
*/
public function get_migration_dir(): string {
return $this->get_root_dir().'/migrate/';
}
/**
* Get an array of variables that should be made available to migrations php files.
*
* @return array<string, object> containing `['db'=>$this]`
*
* @override to make additional vars available to your library's migrations
*/
public function get_migration_vars(): array {
return ['db'=>$this];
}
}